package com.example.chapter3.Dao;

import com.example.chapter3.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface UserDao {
    @Select("select count(1) from user where username = #{name}")
    int findUserByName(String name);
    @Insert("insert into user(username,password,sex) values (#{username},#{password},#{sex})")
    int creatUser(User user);
    @Select("select * from user where username = #{userName}")
    User getUserByName(@Param("userName") String name);
//    @Autowired
//    JdbcTemplate jdbcTemplate;
//    public User getUserByName(String userName){
//        String sql="select * from user where username=?";
//        User user = null;
//        try{
//            user = jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<User>(User.class),userName);
//        } catch (Exception ee){
//
//        }
//        return user;
//    }
}
